<?php
ini_set('display_errors','on');
error_reporting(E_ALL);
require_once 'vendor/autoload.php';
require_once './config.php';
use  GuzzleHttp\Client  as Guzzle;;

class jump
{
    private $curl;
    private $config;

    public function __construct($config)
    {
        $this->curl = new Guzzle();
        $this->config = $config;
    }

    //伙伴物流云合同跳板
    public function jumpToOther()
    {
        $content = @file_get_contents('php://input');

        //过滤不是三方的
        $title = json_decode($content,256)['content'];
        $sub_title = mb_substr($title,0,6);
        if ($sub_title != '运输三方协议') {
            return;
        }

        $reciveYunArr = [
            'data' => $content,
            'time' => date('Y-m-d H:i:s',time()),
        ];
        file_put_contents('./yunRecive.log',json_encode($reciveYunArr,256).PHP_EOL,FILE_APPEND);
        $client = new Guzzle([
            'base_uri' => 'http://118.190.207.192:9165/',
            #'verify' => false,
        ]);
        $res = $client->request('POST','AgreeMent/yunReturn',[
//            'headers' => [
//                'token' => $token,
//                'content-type' => 'application/json;charset=UTF-8',
//            ],
            'body' => $content,
        ]);


        $returnStr = $res->getBody()->getContents();

        $yunReturn = [
            'data' => $returnStr,
            'time' => date('Y-m-d H:i:s',time())
        ];

        if ($returnStr) {
            file_put_contents('./yunReturn.log',json_encode($yunReturn,256).PHP_EOL,FILE_APPEND);
        }
    }
}

$jump = new jump($config); //加载配置文件，并且实例化
$jump->jumpToOther();
